package com.study;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.Random;

public class BitSetStudy {

    public static void main(String[] args) {
        //test1();
        long n = 1232142321312L;

        long n2 = n >> 6;
        System.out.println(n + "," + Long.toBinaryString(n));

        System.out.println(n2 + "," + Long.toBinaryString(n2));

        //1562500
        BitSet bitSet = new BitSet(65);

        new BitSet();

        bitSet.set(1000);

        System.out.println(bitSet.length());

        bitSet.clear(3);

        System.out.println(bitSet.get(2));

        bitSet.cardinality();


        System.out.println(2 >> 6);

        System.out.println(Long.toBinaryString(64));

        System.out.println(Long.toBinaryString(-65));

        System.out.println(Long.toBinaryString(63));
        System.out.println("------");
        //11010101
        //
        System.out.println(Long.toBinaryString(42));

        System.out.println(Long.toBinaryString(~42));

        System.out.println(~42);

        System.out.println("------");


        System.out.println(~(1 << 6));

        System.out.println(~15);
    }

    private static void test1() {
        //        BitSet bitSet = new BitSet(100);
//        bitSet.set(20);
//        System.out.println();

        Random random = new Random();

        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 10000000; i++) {
            int randomResult = random.nextInt(100000000);
            list.add(randomResult);
        }
        System.out.println("产生的随机数有");
//        for(int i=0;i<list.size();i++)
//        {
//            System.out.print("随机数："+list.get(i)+",");
//            if(i % 20 == 0) {
//                System.out.println();
//            }
//        }
        BitSet bitSet = new BitSet(100000000);
        for (int i = 0; i < 10000000; i++) {
            bitSet.set(list.get(i));
        }

        System.out.println("0~1亿不在上述随机数中有" + bitSet.cardinality());
        int n = 0;
        for (int i = 1000000; i < 100000000; i++) {
            long start = System.currentTimeMillis();
            if (!bitSet.get(i)) {
                long end = System.currentTimeMillis();
                System.out.println("耗时:" + (end - start));
            } else {
                long end = System.currentTimeMillis();
                System.out.println("耗时:" + (end - start));
            }
            n++;
            if (n > 100) {
                break;
            }
        }
    }
}
